import Tools from 'tools/index';
import SelectLink from '@/components/SelectLink/directive/app.js';
import SelectAddress from '@/components/SelectAddress/directive/app.js';
import SelectDataGoods from '@/components/SelectDataGoods/directive/app.js';
import SelectDataCoupon from '@/components/SelectDataCoupon/directive/app.js';
import SelectAddressMap from '@/components/SelectAddressMap/directive/app.js';
import SelectDateCycleApplication from '@/components/SelectDateCycleApplication/directive/app.js';
import SelectDataGroupBuying from '@/components/SelectDataGroupBuying/directive/app.js';
import SelectDataLucklyBuying from '@/components/SelectDataLucklyBuying/directive/app.js';
import SelectDataStore from '@/components/SelectDataStore/directive/app.js';
import SelectDataStoreGoods from '@/components/SelectDataStoreGoods/directive/app.js';
import SelectDeliverArea from '@/components/SelectDeliverArea/directive/app.js';
import SelectDataUsers from '@/components/SelectDataUsers/directive/app.js';

export default {
    ...SelectLink,
    ...SelectAddress,
    ...SelectDataGoods,
    ...SelectAddressMap,
    ...SelectDateCycleApplication,
    ...SelectDataLucklyBuying,
    ...SelectDataStore,
    ...SelectDataStoreGoods,
    ...SelectDeliverArea,
    ...SelectDataUsers,
    ...SelectDataGroupBuying,
    ...SelectDataCoupon,
    setConfig(d1_, d2_) {
        // console.error("====d1_, d2_", {...d1_}, {...d2_})
        if (!d1_) {
            d1_ = d2_
        } else {
            for (let i in d2_) {
                d2_[i] = d1_[i] ? d1_[i] : d2_[i];
            }
        }

        // console.error("==== d3_", {...d2_})
        return d2_
    },
    isError(params_) {
        if (params_.appWindow == undefined) {
            alert("组件启动失败，缺少window")
            return false
        } else {
            return true
        }
    },

    // 绘制热区
    async DrawHotspot(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/DrawHotspot/index.js");
        // 关闭加载遮罩层
        Tools.setLoad(false);

        _d.default.init({
            appWindow: params_.appWindow,
            imgUrl: params_.imgUrl,
            hotspotArr: params_.hotspotArr,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },

    // 重置密码 
    async PwdDialog(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/PwdDialog/index.js");
        // 关闭加载遮罩层
        Tools.setLoad(false);

        _d.default.init({
            appWindow: params_.appWindow,
            must: params_.must,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },

    // 修改admin信息
    async UpdateUserInfo(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/UpdateUserInfo/index.js");
        // 关闭加载遮罩层
        Tools.setLoad(false);

        _d.default.init({
            appWindow: params_.appWindow,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },




    // 列表数据删除
    async TableDeleteBox(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/TableDeleteBox/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);
        _d.default.init({
            appWindow: params_.appWindow,
            data: params_.data,
            config: params_.config,
            url: params_.url,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },



    // 上传图片
    async UploadResourcesImage(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/UploadResourcesImage/index");

        let _apiConfig = {
            // 素材分组
            albumList: {
                url: "mall-site-portal/album/listAll",
            },
            // 素材配置
            fileConfig: {
                url: "mall-site-portal/album-info/getFileConfig"
            },
            // 素材创建
            createSubmit: {
                url: "mall-site-portal/album-info/create"
            },
        }

        // 关闭加载遮罩层
        Tools.setLoad(false);
        _d.default.init({
            appWindow: params_.appWindow,
            albumId: params_.albumId,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },
    // 上传视频
    async UploadResourcesVideo(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/UploadResourcesVideo/index");

        let _apiConfig = {
            // 素材分组
            albumList: {
                url: "mall-site-portal/album/listAll"
            },
            // 素材配置
            fileConfig: {
                url: "mall-site-portal/album-info/getFileConfig"
            },
            // 素材创建
            createSubmit: {
                url: "mall-site-portal/album-info/createVideo"
            },
            // 文件上传
            fileUpload: {
                url: "mall-site-portal/oss-upload/upload"
            },
            // 封面上传
            imageUpload: {
                url: "mall-site-portal/oss-upload/uploadBase64"
            },
        }
        // 关闭加载遮罩层
        Tools.setLoad(false);
        _d.default.init({
            appWindow: params_.appWindow,
            albumId: params_.albumId,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },
    // 上传音频
    async UploadResourcesAudio(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/UploadResourcesAudio/index");
        let _apiConfig = {
            // 素材分组
            albumList: {
                url: "mall-site-portal/album/listAll"
            },
            // 素材配置
            fileConfig: {
                url: "mall-site-portal/album-info/getFileConfig"
            },
            // 素材创建
            createSubmit: {
                url: "mall-site-portal/album-info/createVideo"
            },
            // 文件上传
            fileUpload: {
                url: "mall-site-portal/oss-upload/upload"
            },
        }

        // 关闭加载遮罩层
        Tools.setLoad(false);
        _d.default.init({
            appWindow: params_.appWindow,
            albumId: params_.albumId,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },


    // 选择管理员

    async SelectPlatformAdmin(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/SelectPlatformAdmin/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);
        console.error("_d.default", _d.default)
        _d.default.init({
            appWindow: params_.appWindow,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },






    // 选择图片资源
    async SelectResourcesImage(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/SelectResourcesImage/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);

        let _apiConfig = {
            // 素材配置
            fileConfig: {
                url: "mall-site-portal/album-info/getFileConfig",
            },
            // 素材创建
            createSubmit: {
                url: "mall-site-portal/album-info/create",
            },
            // 分组列表
            albumList: {
                url: "mall-site-portal/album/listAll",
            },
            // 分组添加
            albumAdd: {
                url: "mall-site-portal/album/create",
            },
            // 分组删除
            albumDel: {
                url: "mall-site-portal/album/delete",
            },
            // 分组编辑
            albumEdit: {
                url: "mall-site-portal/album/update",
            },
            // 数据列表
            dataList: {
                url: "mall-site-portal/album-info/list",
            },
            // 数据删除
            dataDel: {
                url: "mall-site-portal/album-info/delete",
            },
            // 数据修改
            dataEdit: {
                url: "mall-site-portal/album-info/update",
            },
            // 数据同步
            dataSync: {
                url: "mall-site-portal/album-info/materialUpload",
            },
        }


        if (params_.count == undefined) {
            params_.count = -1
        }
        if (params_.mode == undefined) {
            params_.mode = ""
        }
        _d.default.init({
            appWindow: params_.appWindow,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            count: params_.count,
            mode: params_.mode,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },
    // 选择视频资源
    async SelectResourcesVideo(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/SelectResourcesVideo/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);
        let _apiConfig = {

            // 分组添加 -------------
            albumAdd: {
                url: "mall-site-portal/album/create",
            },
            // 分组删除
            albumDel: {
                url: "mall-site-portal/album/delete",
            },
            // 分组编辑
            albumEdit: {
                url: "mall-site-portal/album/update",
            },

            // 数据列表 ---------------
            dataList: {
                url: "mall-site-portal/album-info/list",
            },
            // 数据删除
            dataDel: {
                url: "mall-site-portal/album-info/delete",
            },
            // 数据修改
            dataEdit: {
                url: "mall-site-portal/album-info/update",
            },
            // 数据同步
            dataSync: {
                url: "mall-site-portal/album-info/materialUpload",
            },

            // 素材分组 ---------------
            albumList: {
                url: "mall-site-portal/album/listAll"
            },
            // 素材配置
            fileConfig: {
                url: "mall-site-portal/album-info/getFileConfig"
            },
            // 素材创建
            createSubmit: {
                url: "mall-site-portal/album-info/createVideo"
            },
            // 文件上传
            fileUpload: {
                url: "mall-site-portal/oss-upload/upload"
            },
            // 封面上传
            imageUpload: {
                url: "mall-site-portal/oss-upload/uploadBase64"
            },
        }
        if (params_.count == undefined) {
            params_.count = -1
        }

        if (params_.mode == undefined) {
            params_.mode = ""
        }

        _d.default.init({
            appWindow: params_.appWindow,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            count: params_.count,
            mode: params_.mode,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },
    // 选择图文资源
    async SelectResourcesWxTuwen(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/SelectResourcesWxTuwen/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);

        if (params_.count == undefined) {
            params_.count = -1
        }

        _d.default.init({
            appWindow: params_.appWindow,
            count: params_.count,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },

    // 选择音频资源
    async SelectResourcesAudio(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/SelectResourcesAudio/index");
        let _apiConfig = {
            // 素材配置
            fileConfig: {
                url: "mall-site-portal/album-info/getFileConfig"
            },
            // 分组列表
            albumList: {
                url: "mall-site-portal/album/listAll",
            },
            // 分组添加
            albumAdd: {
                url: "mall-site-portal/album/create",
            },
            // 分组删除
            albumDel: {
                url: "mall-site-portal/album/delete",
            },
            // 分组编辑
            albumEdit: {
                url: "mall-site-portal/album/update",
            },
            // 数据列表
            dataList: {
                url: "mall-site-portal/album-info/list",
            },
            // 数据删除
            dataDel: {
                url: "mall-site-portal/album-info/delete",
            },
            // 数据修改
            dataEdit: {
                url: "mall-site-portal/album-info/update",
            },
            // 数据同步
            dataSync: {
                url: "mall-site-portal/album-info/materialUpload",
            },
        }
        // 关闭加载遮罩层
        Tools.setLoad(false);

        if (params_.count == undefined) {
            params_.count = -1
        }


        if (params_.mode == undefined) {
            params_.mode = ""
        }
        _d.default.init({
            appWindow: params_.appWindow,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            count: params_.count,
            mode: params_.mode,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },



    // 修改资源
    async UpdateResources(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/UpdateResources/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);
        let _apiConfig = {
            // 数据修改
            dataEdit: {
                url: "mall-site-portal/album-info/update",
            },
            // 分组列表
            albumList: {
                url: "mall-site-portal/album/listAll",
            },
        }
        _d.default.init({
            appWindow: params_.appWindow,
            albumId: params_.albumId,
            id: params_.id,
            type: params_.type,
            name: params_.name,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },



    // 修改微信图文资源
    async UpdateTuwenResources(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/UpdateTuwenResources/index");
        let _apiConfig = {
            // 素材分组
            albumList: {
                url: "mall-site-portal/album/listAll"
            },
            // 素材详情
            dataInfo: {
                url: "mall-site-portal/album-info/getItem"
            },
            // 素材创建
            createSubmit: {
                url: "mall-site-portal/album-info/createNews"
            },
            // 素材修改
            updateSubmit: {
                url: "mall-site-portal/album-info/updateNews"
            },
        }

        // 关闭加载遮罩层
        Tools.setLoad(false);
        if (!params_.type) {
            params_.type = "add"
        }
        _d.default.init({
            appWindow: params_.appWindow,
            type: params_.type,
            albumId: params_.albumId,
            item: params_.item,
            apiConfig: this.setConfig(params_.apiConfig, _apiConfig),
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },



    // 选择微信回复关键词
    async SelectWxReplyKeyword(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/SelectWxReplyKeyword/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);
        _d.default.init({
            appWindow: params_.appWindow,
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
        })
    },



    // 创建商品时选择规格等
    async SelectGoodsSpecs(params_) {
        if (!this.isError(params_)) return
        // 打开加载遮罩层
        Tools.setLoad(true);
        let _d = await import("directives/SelectGoodsSpecs/index");
        // 关闭加载遮罩层
        Tools.setLoad(false);
        if (!params_.model) {
            params_.model = "default"
        }
        _d.default.init({
            appWindow: params_.appWindow,
            model: params_.model,
            textTitle: params_.textTitle,
            list: params_.list,
            listBe: params_.listBe,
            // onCancel: (r) => {
            //     params_.onCancel(r)
            // },
            onSuccess: (r) => {
                params_.onSuccess(r)
            },
            onCreate: async (r, t) => {
                params_.onCreate(r, t)
            },
            onDelete: async (r, t) => {
                params_.onDelete(r, t)
            },
        })

    },
}